//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.finance.framework.controller;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.core.MethodParameter;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.ModelAndViewContainer;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.SmartView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.mvc.method.annotation.ModelAndViewMethodReturnValueHandler;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

public class ResultAndViewMethodReturnValueHandler extends ModelAndViewMethodReturnValueHandler {


    @Override
    public boolean supportsReturnType(MethodParameter methodParameter) {
        return methodParameter.getParameterType() == Result.class;
    }

    @Override
    public void handleReturnValue(Object returnValue, MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest) throws Exception {
        if(returnValue == null) {
            modelAndViewContainer.setRequestHandled(true);
        } else {
            Result result = (Result)returnValue;
            ModelAndView mav = result.getModelAndView();
            if(mav.isReference()) {
                String view = mav.getViewName();
                modelAndViewContainer.setViewName(view);
                if(view != null && this.isRedirectViewName(view)) {
                    modelAndViewContainer.setRedirectModelScenario(true);
                }
            } else {
                View view1 = mav.getView();
                modelAndViewContainer.setView(view1);
                if(view1 instanceof SmartView && ((SmartView)view1).isRedirectView()) {
                    modelAndViewContainer.setRedirectModelScenario(true);
                }
            }
            modelAndViewContainer.getModel().clear();
            modelAndViewContainer.addAllAttributes(mav.getModel());
        }
    }
}
